class window.Door extends window.Tile
    constructor : (@g, @x, @y, @t) ->
        super(@g, @x, @y, @t)
        @open = false
        @locked = true

        @openSpr = [32, 448]
        @closedSpr = [16, 448]
        @doorSpr = @closedSpr
        @hasWall = false



    solid : () ->
        return not @open

    openDoor : (e) ->
        @open = true
        @locked = false
        @doorSpr = @openSpr

    close : (e) ->
        @open = false
        @locked = false
        @doorSpr = @closedSpr

    isWall : () ->
        return true

    getWallSprite : () ->
        t = @wallType()

        return @doorSpr if t == 10
        
        [sx, sy] = @doorSpr
        return [sx, sy - 16]

    touched : (e) ->
        if e.hasTag("cellKey") and @locked and not e.isCarried()
            @openDoor()
            @t.generateTileMesh()
            @g.deleteEntity e


        if (e.hasTag("guard") or e.hasTag("player")) and not @locked
            @openDoor()
            @t.generateTileMesh()